<?php
/**
 * common model file Created by PhpStorm.
 * User: wumengmeng
 * Date: 2019/09/02
 * Time: 09:59
 */

namespace HiCommon\Model;

class InvoiceApply extends Base
{
    
    protected $table = 'invoice_apply';
    protected $guarded = [];
    
    //public $timestamps = false;
    
    /**
     * 应该被调整为日期的属性
     *
     * @var array
     */
    protected $dates = [
    ];
    



    public function getTypeAttribute($value){
        switch ($value)
        {
            case 1:
                $res = ['id'=>1,'name'=>'个人'];
                break;
            case 2:
                $res = ['id'=>2,'name'=>'企业'];
                break;
            default:
                $res = ['id'=>-1,'name'=>'未知'];
        }
        return $res;
    }

    public function getCateAttribute($value){
        switch ($value)
        {
            case 1:
                $res = ['id'=>1,'name'=>'电子版'];
                break;
            case 2:
                $res = ['id'=>2,'name'=>'纸质版'];
                break;
            default:
                $res = ['id'=>-1,'name'=>'未知'];
        }
        return $res;
    }


        /**
         *  关联用户信息
         *  hinq 2019 08 29
         *
         **/
        public function user(){
            return $this->belongsTo(Users::class,'user_id')->select(['username','id','head_img','nickname']);
        }

        /**
         *  关联地址信息
         *  hinq 2019 08 29
         *
         **/
        public function address(){
            return $this->belongsTo(Address::class,'address_id' );
        }

        public function extend(){
            return $this->hasMany(InvoiceApplyExtend::class,'link_id');
        }


  
}